from get_data import GetData
from map import Mapping
from country_name import MappingName

datas = GetData()
datas.get_data()
datas.save_excel()
data = datas.used_data()


class DataMap:
    def __init__(self):
        self.update_time = datas.updated_time()
        self.data_in = data[0]
        self.data_out = data[1]
        self.data_sum_china = data[2]

        self.country_name_en = country_en.modify_name()
        # print(self.country_name_en)
        # print(type(self.country_name_en))

        print('数据更新时间:', self.update_time)

    def china_data_map(self):
        areas = []
        confirmeds = []
        for each in self.data_in:
            areas.append(each['area'])
            confirmeds.append(each['confirmed'])
        map_html.china_map(areas, confirmeds, self.update_time)

    def province_data_map(self):
        for each in self.data_in:
            areas = each['area']
            citys = []
            confirmeds = []
            for eachcity in each['subList']:
                citys.append(eachcity['city'] + "市")
                confirmeds.append(eachcity['confirmed'])
            if areas == '北京' or '上海' or '天津' or '重庆':
                for eachcity in each['subList']:
                    citys.append(eachcity['city'])
                    confirmeds.append(eachcity['confirmed'])
            # if areas == '香港' or '澳门' or '台湾' :  #地图限制，无法显示港澳台整个地区数据
            #     citys.append(each['area'])
            #     confirmeds.append(each['confirmed'])
            map_html.province_map(citys, confirmeds, areas, self.update_time)

    def world_data_map(self):
        areas = []
        confirmeds_sum_china = []
        confirmeds = []
        for each in self.country_name_en:
            areas.append(each)
        areas.append('China')
        for each in self.data_out:
            confirmeds.append(each["confirmed"])
        confirmeds_sum_china = self.data_sum_china['confirmed']
        confirmeds.append(confirmeds_sum_china)
        map_html.world_map(areas, confirmeds, self.update_time)


if __name__ == '__main__':
    map_html = Mapping()

    country_en = MappingName()
    country_en.country_name()
    country_en.modify_name()

    running = DataMap()
    running.china_data_map()
    running.province_data_map()
    running.world_data_map()
